package com.ruoyi.relation.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.relation.domain.DistributionRelation;
import com.ruoyi.relation.service.IDistributionRelationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分销关系信息Controller
 * 
 * @author ruoyi
 * @date 2025-10-11
 */
@RestController
@RequestMapping("/ruoyi/relation")
public class DistributionRelationController extends BaseController
{
    @Autowired
    private IDistributionRelationService distributionRelationService;

    /**
     * 查询分销关系信息列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:relation:list')")
    @GetMapping("/list")
    public TableDataInfo list(DistributionRelation distributionRelation)
    {
        startPage();
        List<DistributionRelation> list = distributionRelationService.selectDistributionRelationList(distributionRelation);
        return getDataTable(list);
    }

    /**
     * 导出分销关系信息列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:relation:export')")
    @Log(title = "分销关系信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DistributionRelation distributionRelation)
    {
        List<DistributionRelation> list = distributionRelationService.selectDistributionRelationList(distributionRelation);
        ExcelUtil<DistributionRelation> util = new ExcelUtil<DistributionRelation>(DistributionRelation.class);
        util.exportExcel(response, list, "分销关系信息数据");
    }

    /**
     * 获取分销关系信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:relation:query')")
    @GetMapping(value = "/{relationId}")
    public AjaxResult getInfo(@PathVariable("relationId") Long relationId)
    {
        return success(distributionRelationService.selectDistributionRelationByRelationId(relationId));
    }

    /**
     * 新增分销关系信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:relation:add')")
    @Log(title = "分销关系信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DistributionRelation distributionRelation)
    {
        return toAjax(distributionRelationService.insertDistributionRelation(distributionRelation));
    }

    /**
     * 修改分销关系信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:relation:edit')")
    @Log(title = "分销关系信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DistributionRelation distributionRelation)
    {
        return toAjax(distributionRelationService.updateDistributionRelation(distributionRelation));
    }

    /**
     * 删除分销关系信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:relation:remove')")
    @Log(title = "分销关系信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{relationIds}")
    public AjaxResult remove(@PathVariable Long[] relationIds)
    {
        return toAjax(distributionRelationService.deleteDistributionRelationByRelationIds(relationIds));
    }
}
